A general explanation from the "Data Model" chapter(http://docs.python.org/reference/datamodel.html#objects-values-and-types) in the Python Language Reference":
"The value of some objects can change. Objects whose value can change are said to be mutable; objects whose value is unchangeable once they are created are called immutable.
(The value of an immutable container object that contains a reference to a mutable object can change when the latter’s value is changed; however the container is still considered immutable, because the collection of objects it contains cannot be changed. So, immutability is not strictly the same as having an unchangeable value, it is more subtle.)
An object’s mutability is determined by its type; for instance, numbers, strings and tuples are immutable, while dictionaries and lists are mutable.
Common immutable type:
Common mutable type (almost everything else):
In [2]:
ls = [1,2,4,5]
print(id(ls))
print(ls)
ls[2]=3
print(id(ls))
print(ls)
Although, immutable elements can not be updated, but mutable elements inside immutables can update themself as shown in the example below.
In [9]:
tp =(1,2,3,4,[2,2,2])
print(tp)
print(id(tp))
tp[4][2]=4
print(tp)
print(id(tp))
In [10]:
print(dir(tp))